import 'package:flutter/material.dart';
import "package:get/get.dart";
import 'package:osg/controllers/http.dart';

class Certification extends StatefulWidget {
   Certification({super.key});

  @override
  State<Certification> createState() => _SettingPageState();
}

late TextEditingController _controller;
late TextEditingController controller;

class _SettingPageState extends State<Certification> {
  RxMap info={}.obs;

  getInfo(){
     Get.find<HTTPS>().getData('/user/idcard', {}).then((res){
            if(res!=null){
              info.value = res;
//               {
//     "is_ok": false,
//     "is_login": true,
//     "true_name": "",
//     "uuid": "68402917b9561",
//     "idcard": "",
//     "phone": ""
// };
            }
          });
  }

  @override
  void initState() {
    super.initState();
    _controller = TextEditingController();
    controller = TextEditingController();

    WidgetsBinding.instance.addPostFrameCallback((_) {
      getInfo();
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final ww = MediaQuery.of(context).size.width;
    final RxBool _isField = true.obs;

    return Scaffold(
        backgroundColor: Color(0xfff5f5f5),
        body: Stack(children: [
          Image.asset(
            'static/images/hometop.png',
            fit: BoxFit.fitWidth,
          ),
          AppBar(
            centerTitle: true,
            backgroundColor: Colors.transparent,
            leadingWidth: 40,
            title: Text(
              '实名认证',
              style: TextStyle(fontSize: 16),
            ),
            leading: IconButton(
              onPressed: () {
                if(info['is_ok']==true){
                Get.back(result: true);
                }else{
                  Get.back();
                }
              },
              icon: Image.asset('static/images/back.png'),
            ),
          ),
          Positioned(
            top: 80,
            width: ww,
            child: Container(
                child: Column(
              children: [
                Obx(()=>
                Image.asset(
                   info['is_ok']==true?
                  'static/images/pl3.png':
                  'static/images/pl1.png'
                  ,
                  fit: BoxFit.fitWidth,
                )
                )
                ,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      margin: EdgeInsets.only(left: 15),
                      child: Text('实名认证', style: TextStyle(fontSize: 12)),
                    ),
                    Text('提交审核', style: TextStyle(fontSize: 12)),
                    Container(
                      margin: EdgeInsets.only(right: 15),
                      child: Text('审核通过', style: TextStyle(fontSize: 12)),
                    ),
                  ],
                ),
              ],
            )),
          ),

            Obx(()=>

            info['is_ok']==true?
            CertificationSuu():
            CertificationText(),//认证中
              
            ),
             Obx(()=>

             info['is_ok']==false?
             Stack(children: [
            Positioned(
                bottom: 50,
                left: 40,
                right: 40,
                child: Column(
                  children: [
                    Text(
                      'OSG将对信息加密，实时保障信息安全',
                      style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                    ),
                    GestureDetector(
                      onTap: (){
                        if(controller.text.isEmpty){
                          Get.find<HTTPS>().showTost('输入姓名');
                          return;
                        }
                        if(_controller.text.isEmpty){
                          Get.find<HTTPS>().showTost('输入证件号码');
                          return;
                        }

                         Get.find<HTTPS>().postData('/user/idcard', {
                              "idcard":_controller.text,
                              "true_name":controller.text,
                            }).then((res){
                              if(res!=null){
                                  getInfo();
                              }
                        });

                      },
                      child: Container(
                      margin: EdgeInsets.only(top: 5),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular((25)),
                        gradient: LinearGradient(
                          colors: [
                            Color(0xff2189E7),
                            Color(0xffBF67F8),
                          ], // 定义颜色列表
                          begin: Alignment.topLeft, // 渐变开始的位置
                          end: Alignment.bottomRight, // 渐变结束的位置
                        ),
                      ),
                      height: 50,
                      child: Text('提交审核',
                          style: TextStyle(
                              fontSize: 16, color: Color(0xffffffff))),
                    ),
                    )
                    ,
                  ],
                ))
          ]):SizedBox(),

        
             )

         
        ]));
  }
}

class CertificationText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final totalHeight = MediaQuery.of(context).padding.top + kToolbarHeight;
    final hh = MediaQuery.of(context).size.height - totalHeight - 100;

    return Container(
        padding: EdgeInsets.only(top: 15, left: 10, right: 10),
        height: hh,
        decoration: BoxDecoration(
          color: Color(0xffffffff),
          borderRadius: BorderRadius.circular(10),
          boxShadow: [
            BoxShadow(
              color: Color.fromRGBO(0, 0, 0, 0.0706), // RGBA透明度转换
              offset: Offset(0, 3), // x=0, y=3rpx
              blurRadius: 30, // 模糊半径30rpx
              spreadRadius: 0, // 扩散半径0rpx
            )
          ],
        ),
        alignment: Alignment.topLeft,
        margin: EdgeInsets.only(left: 15, right: 15, top: 150),
        child: Column(
          children: [
            Align(
              alignment: Alignment.centerLeft, // 左对齐
              child: Text('请核对身份证信息',
                  style: TextStyle(
                    fontSize: 16,
                  )),
            ),
            Align(
              alignment: Alignment.centerLeft, // 左对齐
              child: Text('请确认以下资料并通过认证。',
                  style: TextStyle(fontSize: 12, color: Color(0xff999999))),
            ),
            Container(
                margin: EdgeInsets.only(top: 25),
                height: 50,
                padding: EdgeInsets.only(left: 20),
                decoration: BoxDecoration(
                    color: Color(0xfff5f5f5),
                    borderRadius: BorderRadius.circular(50)),
                child: Row(
                  children: [
                    Padding(
                      padding: EdgeInsets.only(right: 30), // 所有方向上都有16像素的内边距
                      child: Text(
                        '姓名',
                        style: TextStyle(fontSize: 12),
                      ),
                    ),
                    Expanded(
                      child: TextField(
                        controller: controller,
                        style: TextStyle(
                          color: Colors.black, // 文本颜色
                          fontSize: 12.0, // 字体大小
                        ),
                        decoration: InputDecoration(
                          focusedBorder: OutlineInputBorder(
                            borderSide: BorderSide(
                                color: Colors.white, width: 0), // 激活状态下的边框颜色和宽度
                            borderRadius:
                                BorderRadius.circular(20.0), // 设置圆角边框半径
                          ),
                          enabledBorder: OutlineInputBorder(
                            borderSide: BorderSide(
                                color: Colors.white, width: 0), // 激活状态下的边框颜色和宽度
                            borderRadius:
                                BorderRadius.circular(20.0), // 设置圆角边框半径
                          ),
                          filled: true,
                          fillColor: Color(0xfff5f5f5),
                          hintText: '输入真实姓名',
                          hintStyle:
                              TextStyle(fontSize: 12, color: Color(0xff999999)),
                          border: InputBorder.none,
                        ),
                      ),
                    )
                  ],
                )),
            Container(
                margin: EdgeInsets.only(top: 25),
                height: 50,
                padding: EdgeInsets.only(left: 20),
                decoration: BoxDecoration(
                    color: Color(0xfff5f5f5),
                    borderRadius: BorderRadius.circular(50)),
                child: Row(
                  children: [
                    Padding(
                      padding: EdgeInsets.only(right: 6), // 所有方向上都有16像素的内边距
                      child: Text(
                        '证件号码',
                        style: TextStyle(fontSize: 12),
                      ),
                    ),
                    Expanded(
                      child: TextField(
                        controller: _controller,
                        style: TextStyle(
                          color: Colors.black, // 文本颜色
                          fontSize: 12.0, // 字体大小
                        ),
                        decoration: InputDecoration(
                          focusedBorder: OutlineInputBorder(
                            borderSide: BorderSide(
                                color: Colors.white, width: 0), // 激活状态下的边框颜色和宽度
                            borderRadius:
                                BorderRadius.circular(20.0), // 设置圆角边框半径
                          ),
                          enabledBorder: OutlineInputBorder(
                            borderSide: BorderSide(
                                color: Colors.white, width: 0), // 激活状态下的边框颜色和宽度
                            borderRadius:
                                BorderRadius.circular(20.0), // 设置圆角边框半径
                          ),
                          filled: true,
                          fillColor: Color(0xfff5f5f5),
                          hintText: '输入证件号码',
                          hintStyle:
                              TextStyle(fontSize: 12, color: Color(0xff999999)),
                          border: InputBorder.none,
                        ),
                      ),
                    )
                  ],
                )),
          ],
        ));
  }
}

class CertificationSuu extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final totalHeight = MediaQuery.of(context).padding.top + kToolbarHeight;
    final hh = MediaQuery.of(context).size.height - totalHeight - 100;

    return Container(
        padding: EdgeInsets.only(top: 15, left: 10, right: 10),
        height: hh,
        decoration: BoxDecoration(
          color: Color(0xffffffff),
          borderRadius: BorderRadius.circular(10),
          boxShadow: [
            BoxShadow(
              color: Color.fromRGBO(0, 0, 0, 0.0706), // RGBA透明度转换
              offset: Offset(0, 3), // x=0, y=3rpx
              blurRadius: 30, // 模糊半径30rpx
              spreadRadius: 0, // 扩散半径0rpx
            )
          ],
        ),
        alignment: Alignment.center,
        margin: EdgeInsets.only(left: 15, right: 15, top: 150),
        child: Column(
          children: [
            SizedBox(
              height: 100,
            ),
            Image.asset(
              'static/images/tongguo.png',
              width: 80,
            ),
            SizedBox(
              height: 10,
            ),
            Text(
              '您已通过认证，可以开启直播啦!',
              style: TextStyle(fontSize: 12, color: Color(0xff999999)),
            ),
            SizedBox(
              height: 130,
            ),
            GestureDetector(
              onTap: () => {Get.toNamed('/live_seeting')},
              child: Container(
                margin: EdgeInsets.only(top: 5, left: 30, right: 30),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular((25)),
                  gradient: LinearGradient(
                    colors: [
                      Color(0xff2189E7),
                      Color(0xffBF67F8),
                    ], // 定义颜色列表
                    begin: Alignment.topLeft, // 渐变开始的位置
                    end: Alignment.bottomRight, // 渐变结束的位置
                  ),
                ),
                height: 50,
                child: Text('开启直播',
                    style: TextStyle(fontSize: 16, color: Color(0xffffffff))),
              ),
            ),
            SizedBox(
              height: 30,
            ),
            GestureDetector(
              onTap: (){
                Get.offAllNamed('/');
              },
              child: Text(
              '返回个人中心',
              style: TextStyle(fontSize: 12, color: Color(0xff999999)),
            ),
            )
            ,
          ],
        ));
  }
}
